package com.foreknow.dao.impl;

import com.foreknow.bean.Sys_User;
import com.foreknow.dao.Sys_UserDao;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.mapping.MappingFactory;

import java.sql.SQLException;
import java.util.List;

public class Sys_UserDaoImpl extends  BaseDao implements Sys_UserDao {
    @Override
    public boolean addSys_User(Sys_User sys_user) throws SQLException {
        String sql = "insert into sys_user(id,name,sex,age,marry,addr,num) values(?,?,?,?,?,?,?)";
        int x = jdbcTemplate.update(sql,sys_user.getId(),sys_user.getName(),sys_user.getSex(),sys_user.getAge(),sys_user.getMarry(),sys_user.getAddr(),sys_user.getNum());
        return x == 1;
    }

    @Override
    public boolean updateSys_User(Sys_User sys_user) {
        String sql = "update sys_user set name=?,sex=?,age?,marry=?,addr=?,num=?where id=?";
        int isRight = jdbcTemplate.update(sql,sys_user.getId(),sys_user.getName(),sys_user.getSex(),sys_user.getAge(),sys_user.getMarry(),sys_user.getAddr(),sys_user.getNum());
        return isRight==1;

    }

    @Override
    public Sys_User queryById(String id) {
        String sql = "select * from sys_user where id=?";
        EntityMapping mapping = mappingFactory.getMap(MappingFactory.Sys_User_MAPPING);
        List<Object> list = jdbcTemplate.query(sql,mapping,id);
        Sys_User sys_user= null;
        if(list.size()>0){
            sys_user = (Sys_User) list.get(0);
        }
        return sys_user;
    }



    @Override
    public List<Object> getQuaryall() {
        String sql = "select * from sys_user";
        EntityMapping mapping =mappingFactory.getMap(MappingFactory.Sys_User_MAPPING);
        List<Object> list =  jdbcTemplate.query(sql,mapping);
       return list;
    }

    @Override
    public boolean deletByid(String id) {
        String sql = "delete fromsys _user where id=?";
        int isRight = jdbcTemplate.update(sql,id);
        return isRight==1;

    }

    @Override
    public boolean save(Sys_User sys_user) {
        return false;
    }
}
